/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * QueuePolicySettingsFrame.java
 *
 * Created on 2010-06-05, 12:21:36
 */

package nsdh.view;

import nsdh.*;
import nsdh.model.script_models.*;
import javax.swing.table.*;
import javax.swing.*;
import java.util.Set;
import java.util.HashSet;
import java.util.HashMap;
import nsdh.model.script_models.*;
import javax.swing.event.*;


/**
 *
 * @author vtq
 */
public class QueuePolicySettingsFrame extends javax.swing.JFrame {

    /** Creates new form QueuePolicySettingsFrame */
    public QueuePolicySettingsFrame(NsdhController nsdhController, GraphPanel graphPanel, NetworkSettingsFrame networkSettingsFrame, String queuePolicyName) {
        initComponents();
        this.nsdhController = nsdhController;
        this.graphPanel = graphPanel;
        this.queuePolicyName = queuePolicyName;
        this.networkSettingsFrame = networkSettingsFrame;

        createQueuesTableFields();
        //createPolicyEntriesTableFields("");
        createSchedulerParamsTableFields();
        createSubqueueParamsTableFields();

        this.tempQueueList = new HashMap<String,Queue>(); //tymczasowa zmienna

        //jesli edycja to wczytaj
        if(queuePolicyName!=null && !queuePolicyName.equals("")){
            loadQueuePolicySettingsFromNsdhModel();
            loadQueuesTableFromNsdhModel();
        }


        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        queuesPanel = new javax.swing.JPanel();
        queuesScrollPane = new javax.swing.JScrollPane();
        queuesTable = new javax.swing.JTable();
        policyEntriesPanel = new javax.swing.JPanel();
        policyEntriesScrollPane = new javax.swing.JScrollPane();
        policyEntriesTable = new javax.swing.JTable();
        policyEntriesAddButton = new javax.swing.JButton();
        policyEntriesRemoveButton = new javax.swing.JButton();
        subqueueParamsPanel = new javax.swing.JPanel();
        subqueueParamsScrollPane = new javax.swing.JScrollPane();
        subqueueParamsTable = new javax.swing.JTable();
        queuesAddButton = new javax.swing.JButton();
        queuesRemoveButton = new javax.swing.JButton();
        schedulerParamsPanel = new javax.swing.JPanel();
        schedulerParamsScrollPane = new javax.swing.JScrollPane();
        schedulerParamsTable = new javax.swing.JTable();
        policerComboBox = new javax.swing.JComboBox();
        policerLabel = new javax.swing.JLabel();
        subqueueCountLabel = new javax.swing.JLabel();
        subqueueCountComboBox = new javax.swing.JComboBox();
        okButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        queuePolicyParamsPanel = new javax.swing.JPanel();
        schedulerLabel = new javax.swing.JLabel();
        avgPacketTextField = new javax.swing.JTextField();
        schedulerComboBox = new javax.swing.JComboBox();
        avgPacketLabel = new javax.swing.JLabel();
        queuePolicyNameTextField = new javax.swing.JTextField();
        queuePolicyNameLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Parametry polityki kolejkowania");

        queuesPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Kolejki"));

        queuesTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        queuesScrollPane.setViewportView(queuesTable);

        policyEntriesPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Kolejkowane usługi i parametry dla policer'a"));

        policyEntriesTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        policyEntriesScrollPane.setViewportView(policyEntriesTable);

        policyEntriesAddButton.setText("Dodaj");
        policyEntriesAddButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                policyEntriesAddButtonActionPerformed(evt);
            }
        });

        policyEntriesRemoveButton.setText("Usun");
        policyEntriesRemoveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                policyEntriesRemoveButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout policyEntriesPanelLayout = new javax.swing.GroupLayout(policyEntriesPanel);
        policyEntriesPanel.setLayout(policyEntriesPanelLayout);
        policyEntriesPanelLayout.setHorizontalGroup(
            policyEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, policyEntriesPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(policyEntriesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 460, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(policyEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(policyEntriesRemoveButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(policyEntriesAddButton, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE))
                .addContainerGap())
        );
        policyEntriesPanelLayout.setVerticalGroup(
            policyEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(policyEntriesPanelLayout.createSequentialGroup()
                .addGroup(policyEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(policyEntriesPanelLayout.createSequentialGroup()
                        .addComponent(policyEntriesAddButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(policyEntriesRemoveButton))
                    .addComponent(policyEntriesScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        subqueueParamsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Parametry podkolejek"));

        subqueueParamsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        subqueueParamsScrollPane.setViewportView(subqueueParamsTable);

        javax.swing.GroupLayout subqueueParamsPanelLayout = new javax.swing.GroupLayout(subqueueParamsPanel);
        subqueueParamsPanel.setLayout(subqueueParamsPanelLayout);
        subqueueParamsPanelLayout.setHorizontalGroup(
            subqueueParamsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(subqueueParamsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(subqueueParamsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 556, Short.MAX_VALUE)
                .addContainerGap())
        );
        subqueueParamsPanelLayout.setVerticalGroup(
            subqueueParamsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(subqueueParamsPanelLayout.createSequentialGroup()
                .addComponent(subqueueParamsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE)
                .addContainerGap())
        );

        queuesAddButton.setText("Dodaj");
        queuesAddButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                queuesAddButtonActionPerformed(evt);
            }
        });

        queuesRemoveButton.setText("Usun");
        queuesRemoveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                queuesRemoveButtonActionPerformed(evt);
            }
        });

        schedulerParamsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Parametry scheduler'a dla kolejki"));

        schedulerParamsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        schedulerParamsScrollPane.setViewportView(schedulerParamsTable);

        javax.swing.GroupLayout schedulerParamsPanelLayout = new javax.swing.GroupLayout(schedulerParamsPanel);
        schedulerParamsPanel.setLayout(schedulerParamsPanelLayout);
        schedulerParamsPanelLayout.setHorizontalGroup(
            schedulerParamsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(schedulerParamsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(schedulerParamsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 556, Short.MAX_VALUE)
                .addContainerGap())
        );
        schedulerParamsPanelLayout.setVerticalGroup(
            schedulerParamsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, schedulerParamsPanelLayout.createSequentialGroup()
                .addComponent(schedulerParamsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)
                .addContainerGap())
        );

        policerComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "TSW2CM", "TSW3CM", "TokenBucket", "srTCM", "trTCM", "NullPolicer", "Brak" }));
        policerComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                policerComboBoxActionPerformed(evt);
            }
        });

        policerLabel.setText("Typ Policera w kolejce:");

        subqueueCountLabel.setText("Liczba podkolejek:");

        subqueueCountComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3" }));
        subqueueCountComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                subqueueCountComboBoxActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout queuesPanelLayout = new javax.swing.GroupLayout(queuesPanel);
        queuesPanel.setLayout(queuesPanelLayout);
        queuesPanelLayout.setHorizontalGroup(
            queuesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(queuesPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(queuesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(queuesPanelLayout.createSequentialGroup()
                        .addComponent(queuesAddButton, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(queuesRemoveButton, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE))
                    .addGroup(queuesPanelLayout.createSequentialGroup()
                        .addComponent(queuesScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(queuesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, queuesPanelLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(subqueueCountLabel)
                        .addGap(41, 41, 41)
                        .addComponent(subqueueCountComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, queuesPanelLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(queuesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(subqueueParamsPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(policyEntriesPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(schedulerParamsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(queuesPanelLayout.createSequentialGroup()
                                .addGap(8, 8, 8)
                                .addComponent(policerLabel)
                                .addGap(16, 16, 16)
                                .addComponent(policerComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );
        queuesPanelLayout.setVerticalGroup(
            queuesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(queuesPanelLayout.createSequentialGroup()
                .addGroup(queuesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(queuesPanelLayout.createSequentialGroup()
                        .addGroup(queuesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(queuesRemoveButton)
                            .addComponent(queuesAddButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(queuesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE))
                    .addGroup(queuesPanelLayout.createSequentialGroup()
                        .addComponent(schedulerParamsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(queuesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(policerComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(policerLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(policyEntriesPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(queuesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(subqueueCountLabel)
                            .addComponent(subqueueCountComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(subqueueParamsPanel, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );

        okButton.setText("OK");
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        cancelButton.setText("Anuluj");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        queuePolicyParamsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Parametry polityki kolejkowania"));

        schedulerLabel.setText("Typ scheduler'a:");

        schedulerComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "PRI", "WRR", "WIRR", "RR" }));
        schedulerComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                schedulerComboBoxActionPerformed(evt);
            }
        });

        avgPacketLabel.setText("Śr. wielkość pakietu [B]:");

        queuePolicyNameLabel.setText("Nazwa:");

        javax.swing.GroupLayout queuePolicyParamsPanelLayout = new javax.swing.GroupLayout(queuePolicyParamsPanel);
        queuePolicyParamsPanel.setLayout(queuePolicyParamsPanelLayout);
        queuePolicyParamsPanelLayout.setHorizontalGroup(
            queuePolicyParamsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(queuePolicyParamsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(queuePolicyParamsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(schedulerLabel)
                    .addComponent(queuePolicyNameLabel)
                    .addComponent(avgPacketLabel))
                .addGap(52, 52, 52)
                .addGroup(queuePolicyParamsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(avgPacketTextField)
                    .addComponent(queuePolicyNameTextField)
                    .addComponent(schedulerComboBox, 0, 160, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        queuePolicyParamsPanelLayout.setVerticalGroup(
            queuePolicyParamsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(queuePolicyParamsPanelLayout.createSequentialGroup()
                .addGroup(queuePolicyParamsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(queuePolicyNameLabel)
                    .addComponent(queuePolicyNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(queuePolicyParamsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(schedulerLabel)
                    .addComponent(schedulerComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(queuePolicyParamsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(avgPacketLabel)
                    .addComponent(avgPacketTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(queuePolicyParamsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(queuesPanel, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(293, 293, 293)
                        .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(queuePolicyParamsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addComponent(queuesPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(okButton)
                    .addComponent(cancelButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void policyEntriesAddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_policyEntriesAddButtonActionPerformed
        DefaultTableModel model = (DefaultTableModel)policyEntriesTable.getModel();
        Object[] newRow = {""};

        if(policyEntriesTable.isEditing()){
            policyEntriesTable.editingStopped(new ChangeEvent(policyEntriesAddButton));
        }
        model.fireTableDataChanged();
        model.insertRow(model.getRowCount(), newRow);
        model.fireTableDataChanged();

        policyEntriesTable.requestFocusInWindow();
}//GEN-LAST:event_policyEntriesAddButtonActionPerformed

    private void policyEntriesRemoveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_policyEntriesRemoveButtonActionPerformed
        DefaultTableModel model = (DefaultTableModel)policyEntriesTable.getModel();

        int[] selectedRows = policyEntriesTable.getSelectedRows();

        java.util.Arrays.sort(selectedRows);
        for(int i=selectedRows.length-1; i>= 0; i--){
            if(policyEntriesTable.isEditing()){
                policyEntriesTable.editingStopped(new ChangeEvent(policyEntriesRemoveButton));
            }
            model.fireTableDataChanged();
            model.removeRow(selectedRows[i]);
            model.fireTableDataChanged();

            policyEntriesTable.requestFocusInWindow();

        }
}//GEN-LAST:event_policyEntriesRemoveButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        this.dispose();
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        try{
            saveQueuePolicyToNsdhModel();
            networkSettingsFrame.LoadQueuePolicyTableFromNsdhModel();
            this.dispose();
        }catch(Exception e){
            JOptionPane.showMessageDialog(this, e.getMessage(), "Ostrzeżenie", JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_okButtonActionPerformed

    private void queuesAddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_queuesAddButtonActionPerformed
        DefaultTableModel model = (DefaultTableModel)queuesTable.getModel();
        Object[] newRow = {""};
        model.insertRow(model.getRowCount(), newRow);
    }//GEN-LAST:event_queuesAddButtonActionPerformed

    private void policerComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_policerComboBoxActionPerformed

        if(((String)policerComboBox.getSelectedItem()).equals("Brak")){
            
            //wczytaj aktualnie otwarta kolejke
            Queue tempQueue = new Queue();
            DefaultTableModel queuesTableModel = (DefaultTableModel)queuesTable.getModel();
            if(tempQueueList.containsKey((String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0))){
                tempQueue = tempQueueList.get((String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0));
            }else if(queuePolicyName!=null && !queuePolicyName.equals("")
                    && nsdhController.getQueueIndexOnListInQueuePolicy(nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName),(String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0))!=-1){
                tempQueue = nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName).queue_list.get(nsdhController.getQueueIndexOnListInQueuePolicy(nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName),(String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0)));
            }
            //ustaw ilosc podkolejek gdy brak policera
            subqueueCountComboBox.setSelectedItem(String.valueOf(tempQueue.subqueue_list.size()));

        }



        updatePolicerAndSubqueueSettings();
    }//GEN-LAST:event_policerComboBoxActionPerformed

    private void schedulerComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_schedulerComboBoxActionPerformed
        if(queuesTable.getSelectedRow()!=-1){
            
            
            createSchedulerParamsTableFields();
            //createSubqueueParamsTableFields();
            //Sprawdz czy kolejka nie byla juz zapisana w tymczasowej tablicy ani nie ma jej w modelu, jesli jest to zaladuj
            DefaultTableModel queuesTableModel = (DefaultTableModel)queuesTable.getModel();
            Queue tempQueue = new Queue();
            if(tempQueueList.containsKey((String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0))){
                tempQueue = tempQueueList.get((String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0));
            }else if(queuePolicyName!=null && !queuePolicyName.equals("")
                    && nsdhController.getQueueIndexOnListInQueuePolicy(nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName),(String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0))!=-1){
                tempQueue = nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName).queue_list.get(nsdhController.getQueueIndexOnListInQueuePolicy(nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName),(String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0)));
            }
            loadSchedulerParamsTableFromModel(tempQueue);
            //loadSubqueueParamsTableFromModel(tempQueue);
        }
    }//GEN-LAST:event_schedulerComboBoxActionPerformed

    private void queuesRemoveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_queuesRemoveButtonActionPerformed
        DefaultTableModel model = (DefaultTableModel)queuesTable.getModel();

        int[] selectedRows = queuesTable.getSelectedRows();

        java.util.Arrays.sort(selectedRows);
        for(int i=selectedRows.length-1; i>= 0; i--){
            if(queuesTable.isEditing()){
                queuesTable.editingStopped(new ChangeEvent(queuesRemoveButton));
            }
            model.fireTableDataChanged();
            model.removeRow(selectedRows[i]);
            model.fireTableDataChanged();

            queuesTable.requestFocusInWindow();

        }
    }//GEN-LAST:event_queuesRemoveButtonActionPerformed

    private void subqueueCountComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_subqueueCountComboBoxActionPerformed
        updatePolicerAndSubqueueSettings();
    }//GEN-LAST:event_subqueueCountComboBoxActionPerformed


    private void updatePolicerAndSubqueueSettings(){
        if(queuesTable.getSelectedRow()!=-1){
            //createSchedulerParamsTableFields();
            createSubqueueParamsTableFields();
            String policerType = (String)policerComboBox.getSelectedItem();

            if(policerType.equals("Brak")){
                policerType = "None";
            }
            this.createPolicyEntriesTableFields(policerType);
            //Sprawdz czy kolejka nie byla juz zapisana w tymczasowej tablicy ani nie ma jej w modelu, jesli jest to zaladuj
            DefaultTableModel queuesTableModel = (DefaultTableModel)queuesTable.getModel();
            Queue tempQueue = new Queue();
            if(tempQueueList.containsKey((String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0))){
                tempQueue = tempQueueList.get((String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0));
            }else if(queuePolicyName!=null && !queuePolicyName.equals("")
                    && nsdhController.getQueueIndexOnListInQueuePolicy(nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName),(String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0))!=-1){
                tempQueue = nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName).queue_list.get(nsdhController.getQueueIndexOnListInQueuePolicy(nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName),(String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0)));
            }

            //loadSchedulerParamsTableFromModel(tempQueue);
            loadSubqueueParamsTableFromModel(tempQueue);
        }
    }

    private void loadQueuePolicySettingsFromNsdhModel(){

        avgPacketTextField.setText(nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName).mean_packet_size);
        queuePolicyNameTextField.setText(nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName).name);

        
        schedulerComboBox.setSelectedItem(nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName).scheduler);

    }

    private void createQueuesTableFields(){

        String[] values = new String[]{"Lista"};
        queuesTable.setModel(new DefaultTableModel(values,0) {
                                 @Override
                                 //nazwe mozna edytowac
                                 public boolean isCellEditable(int row, int column)
                                 {
                                         return true;
                                 }
                             }
                );
        DefaultTableModel model = (DefaultTableModel)queuesTable.getModel();




        queuesTable.getSelectionModel().addListSelectionListener(new queueRowSelectionListener());


    }


    private void loadQueuesTableFromNsdhModel(){

        DefaultTableModel model = (DefaultTableModel)queuesTable.getModel();

        for (int i=0; i< nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName).queue_list.size(); i++ ){
            String[] rowArray = new String[1];
            rowArray[0] = nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName).queue_list.get(i).name;
            model.addRow(rowArray);
        }

    }

    private void createPolicyEntriesTableFields(String policerType){

        String[] values = new String[]{""};
        if(policerType.equals("None")){
            values = new String[]{""};
            disablePolicerSettings();
        }
        else if(policerType.equals("NullPolicer")){
            values = new String[]{"Usługa"};
            subqueueCountComboBox.setSelectedItem("1");
            enablePolicerSettings();
        }else if(policerType.equals("TSW2CM")){
            values = new String[]{"Usługa","CIR [bps]"};
            subqueueCountComboBox.setSelectedItem("2");
            enablePolicerSettings();
        }else if(policerType.equals("TSW3CM")){
            values = new String[]{"Usługa","CIR [bps]","PIR [bps]"};
            subqueueCountComboBox.setSelectedItem("3");
            enablePolicerSettings();
        }else if(policerType.equals("TokenBucket")){
            values = new String[]{"Usługa","CIR [bps]","CBS [B]"};
            subqueueCountComboBox.setSelectedItem("2");
            enablePolicerSettings();
        }else if(policerType.equals("srTCM")){
            values = new String[]{"Usługa","CIR [bps]","CBS [B]","EBS [B]"};
            subqueueCountComboBox.setSelectedItem("3");
            enablePolicerSettings();
        }else if(policerType.equals("trTCM")){
            values = new String[]{"Usługa","CIR [bps]","CBS [B]","PIR [bps]","PBS [B]"};
            subqueueCountComboBox.setSelectedItem("3");
            enablePolicerSettings();
        }

        policyEntriesTable.setModel(new DefaultTableModel(values,0) {
                                 @Override
                                 //nazwe mozna edytowac
                                 public boolean isCellEditable(int row, int column)
                                 {
                                         return true;
                                 }
                             }
                );
        DefaultTableModel model = (DefaultTableModel)policyEntriesTable.getModel();

        //tablica i combobox uslug
        Set<String> serviceNameSet = new HashSet(nsdhController.nsdhModel.network_settings.service_list.keySet());
        serviceNameSet.add("");
        Object[] serviceNameArray = serviceNameSet.toArray();
        java.util.Arrays.sort(serviceNameArray);

        JComboBox serviceComboBox = new JComboBox();
        serviceComboBox.setModel(new javax.swing.DefaultComboBoxModel(serviceNameArray));

        //dodaje combox do tabeli
        policyEntriesTable.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(serviceComboBox));




    }

    private void disablePolicerSettings(){

        policyEntriesTable.setEnabled(false);
        policyEntriesAddButton.setEnabled(false);
        policyEntriesRemoveButton.setEnabled(false);
        subqueueCountComboBox.setEnabled(true);
    }

    private void enablePolicerSettings(){

        policyEntriesTable.setEnabled(true);
        policyEntriesAddButton.setEnabled(true);
        policyEntriesRemoveButton.setEnabled(true);
        subqueueCountComboBox.setEnabled(false);

    }


    private void loadPolicerSettingsFromModel(Queue queue){

        //typ policera w kolejce
        if(queue.policer.equals("")){
            queue.policer = "TSW2CM";
        }

        if(queue.policer.equals("None")){
            policerComboBox.setSelectedItem("Brak");
        }else{
            policerComboBox.setSelectedItem(queue.policer);
        }

        
        //zainicjalizuj kolumny tabeli z wpisami policera
        createPolicyEntriesTableFields(queue.policer);
        
        //model
        DefaultTableModel policyEntriesTableModel = (DefaultTableModel)policyEntriesTable.getModel();


        //String selectedQueueName = (String)queuesTableModel.getValueAt(0, queuesTable.getSelectedRow());

        for(Policer_entry policer_entry: queue.policer_entry_list.values()){

            String[] rowArray;

            if(queue.policer.equals("NullPolicer")){
                rowArray = new String[1];
                rowArray[0] = policer_entry.service;
                policyEntriesTableModel.addRow(rowArray);
            }else if(queue.policer.equals("TSW2CM")){
                rowArray = new String[2];
                rowArray[0] = policer_entry.service;
                rowArray[1] = policer_entry.CIR;
                policyEntriesTableModel.addRow(rowArray);
            }else if(queue.policer.equals("TSW3CM")){
                rowArray = new String[3];
                rowArray[0] = policer_entry.service;
                rowArray[1] = policer_entry.CIR;
                rowArray[2] = policer_entry.PIR;
                policyEntriesTableModel.addRow(rowArray);
            }else if(queue.policer.equals("TokenBucket")){
                rowArray = new String[3];
                rowArray[0] = policer_entry.service;
                rowArray[1] = policer_entry.CIR;
                rowArray[2] = policer_entry.CBS;
                policyEntriesTableModel.addRow(rowArray);
            }else if(queue.policer.equals("srTCM")){
                rowArray = new String[4];
                rowArray[0] = policer_entry.service;
                rowArray[1] = policer_entry.CIR;
                rowArray[2] = policer_entry.CBS;
                rowArray[3] = policer_entry.EBS;
                policyEntriesTableModel.addRow(rowArray);
            }else if(queue.policer.equals("trTCM")){
                rowArray = new String[5];
                rowArray[0] = policer_entry.service;
                rowArray[1] = policer_entry.CIR;
                rowArray[2] = policer_entry.CBS;
                rowArray[3] = policer_entry.PIR;
                rowArray[3] = policer_entry.PBS;
                policyEntriesTableModel.addRow(rowArray);
            }

            
        }

        


    }

    private void createSchedulerParamsTableFields(){

        String[] values = new String[]{"Nazwa","Wartość"};
        schedulerParamsTable.setModel(new DefaultTableModel(values,0) {
                                 @Override
                                 //nazwe mozna edytowac
                                 public boolean isCellEditable(int row, int column)
                                 {
                                         if (column==0)
                                             return false;
                                         else
                                             return true;
                                 }
                             }
                );
        DefaultTableModel model = (DefaultTableModel)schedulerParamsTable.getModel();

    }


    private void loadSchedulerParamsTableFromModel(Queue queue){
        createSchedulerParamsTableFields();
        DefaultTableModel model = (DefaultTableModel)schedulerParamsTable.getModel();

        String[] rowArray = new String[2];


        //parametry schedulera
        //scheduler PRI
        if(schedulerComboBox.getSelectedIndex()==0){
            //parametr priority
            rowArray[0] = "priority";
            rowArray[1] = queue.scheduler_params.priority;
            model.addRow(rowArray);

            //parametr rate
            rowArray[0] = "rate [bps]";
            rowArray[1] = queue.scheduler_params.rate;
            model.addRow(rowArray);

        }else{//scheduler RR,WIRR,WRR
            rowArray[0] = "weight";
            rowArray[1] = queue.scheduler_params.weight;

            model.addRow(rowArray);
        }

    }

    private void createSubqueueParamsTableFields(){

        String[] values = new String[]{"#","min_threshold","max_threshold","probability_dropping"};
        subqueueParamsTable.setModel(new DefaultTableModel(values,0) {
                                 @Override
                                 //nazwe mozna edytowac
                                 public boolean isCellEditable(int row, int column)
                                 {
                                         if (column==0)
                                             return false;
                                         else
                                             return true;
                                 }
                             }
                );
        DefaultTableModel model = (DefaultTableModel)subqueueParamsTable.getModel();

    }


    private void loadSubqueueParamsTableFromModel(Queue queue){

        createSubqueueParamsTableFields();

        DefaultTableModel model = (DefaultTableModel)subqueueParamsTable.getModel();
        String[] rowArray = new String[4];

        if(((String)policerComboBox.getSelectedItem()).equals("Brak")){

            

            int subqueueCount = Integer.parseInt((String)subqueueCountComboBox.getSelectedItem());

            for(int i=0; i < queue.subqueue_list.size() && i<subqueueCount;i++){
                rowArray[0] = queue.subqueue_list.get(i).ordinal;
                rowArray[1] = queue.subqueue_list.get(i).min_threshold;
                rowArray[2] = queue.subqueue_list.get(i).max_threshold;
                rowArray[3] = queue.subqueue_list.get(i).probability_dropping;
                model.addRow(rowArray);
            }

            //dodaj puste wiersze jesli zla ilosc
            for(int i=queue.subqueue_list.size(); i< subqueueCount; i++){
                rowArray[0]=Integer.toString(i);
                rowArray[1]="";
                rowArray[2]="";
                rowArray[3]="";
                model.addRow(rowArray);
            }
        }

        else if(((String)policerComboBox.getSelectedItem()).equals("NullPolicer")){ //dla policera null - jedna kolejka

            for(int i=0; i < queue.subqueue_list.size() && i<1;i++){
                rowArray[0] = queue.subqueue_list.get(i).ordinal;
                rowArray[1] = queue.subqueue_list.get(i).min_threshold;
                rowArray[2] = queue.subqueue_list.get(i).max_threshold;
                rowArray[3] = queue.subqueue_list.get(i).probability_dropping;
                model.addRow(rowArray);
            }

            //dodaj puste wiersze jesli zla ilosc
            for(int i=queue.subqueue_list.size(); i< 1; i++){
                rowArray[0]=Integer.toString(i);
                rowArray[1]="";
                rowArray[2]="";
                rowArray[3]="";
                model.addRow(rowArray);
            }

        }

        else if(((String)policerComboBox.getSelectedItem()).equals("TSW2CM") || ((String)policerComboBox.getSelectedItem()).equals("TokenBucket")){//"TSW2CM" lub TokenBucket - 2 podkolejki
            
            for(int i=0; i < queue.subqueue_list.size() && i<2;i++){
                rowArray[0] = queue.subqueue_list.get(i).ordinal;
                rowArray[1] = queue.subqueue_list.get(i).min_threshold;
                rowArray[2] = queue.subqueue_list.get(i).max_threshold;
                rowArray[3] = queue.subqueue_list.get(i).probability_dropping;
                model.addRow(rowArray);
            }

            //dodaj puste wiersze jesli zla ilosc
            for(int i=queue.subqueue_list.size(); i< 2; i++){
                rowArray[0]=Integer.toString(i);
                rowArray[1]="";
                rowArray[2]="";
                rowArray[3]="";
                model.addRow(rowArray);
            }

        }else { //w przeciwnym przypadku (inny policer) 3 podkolejki

            for(int i=0; i < queue.subqueue_list.size();i++){
                rowArray[0] = queue.subqueue_list.get(i).ordinal;
                rowArray[1] = queue.subqueue_list.get(i).min_threshold;
                rowArray[2] = queue.subqueue_list.get(i).max_threshold;
                rowArray[3] = queue.subqueue_list.get(i).probability_dropping;
                model.addRow(rowArray);
            }

            //dodaj puste wiersze jesli zla ilosc
            for(int i=queue.subqueue_list.size(); i< 3; i++){
                rowArray[0]=Integer.toString(i);
                rowArray[1]="";
                rowArray[2]="";
                rowArray[3]="";
                model.addRow(rowArray);
            }

        }

    }

    /**
     * Tworzy obiekt kolejka na podstawie wypelnionego formularza (oprocz nazwy)
     * @return
     */
    private Queue getQueueObjectFromFilledForm(){

        Queue tempQueue = new Queue();
        //model tabeli kolejek
        DefaultTableModel queuesTableModel = (DefaultTableModel)queuesTable.getModel();

        //koncz edycje komorek jesli jakies sa edytowane
        if(policyEntriesTable.getCellEditor()!=null){
            policyEntriesTable.getCellEditor().stopCellEditing();
        }
        if(schedulerParamsTable.getCellEditor()!=null){
            schedulerParamsTable.getCellEditor().stopCellEditing();
        }
        if(subqueueParamsTable.getCellEditor()!=null){
            subqueueParamsTable.getCellEditor().stopCellEditing();
        }

        //------ typ policera ------------------------------------

        tempQueue.policer = (String)policerComboBox.getSelectedItem();
        if(tempQueue.policer.equals("Brak")){
            tempQueue.policer = "None";
        }

        //------------wpisy policera------------------
        DefaultTableModel policyEntriesTableModel = (DefaultTableModel)policyEntriesTable.getModel();

        for(int i=0;i<policyEntriesTableModel.getRowCount();i++){
            Policer_entry policer_entry = new Policer_entry();

            //dla wszystkich policerow (w tym null)
            policer_entry.service = (String)policyEntriesTableModel.getValueAt(i, 0);

            //dla policerow innych niz null
            if(tempQueue.policer.equals("TSW2CM")){
                policer_entry.CIR = (String)policyEntriesTableModel.getValueAt(i, 1);
            }else if(tempQueue.policer.equals("TSW3CM")){
                policer_entry.CIR = (String)policyEntriesTableModel.getValueAt(i, 1);
                policer_entry.PIR = (String)policyEntriesTableModel.getValueAt(i, 2);
            }else if(tempQueue.policer.equals("TokenBucket")){
                policer_entry.CIR = (String)policyEntriesTableModel.getValueAt(i, 1);
                policer_entry.CBS = (String)policyEntriesTableModel.getValueAt(i, 2);
            }else if(tempQueue.policer.equals("srTCM")){
                policer_entry.CIR = (String)policyEntriesTableModel.getValueAt(i, 1);
                policer_entry.CBS = (String)policyEntriesTableModel.getValueAt(i, 2);
                policer_entry.EBS = (String)policyEntriesTableModel.getValueAt(i, 3);
            }else if(tempQueue.policer.equals("trTCM")){
                policer_entry.CIR = (String)policyEntriesTableModel.getValueAt(i, 1);
                policer_entry.CBS = (String)policyEntriesTableModel.getValueAt(i, 2);
                policer_entry.PIR = (String)policyEntriesTableModel.getValueAt(i, 3);
                policer_entry.PBS = (String)policyEntriesTableModel.getValueAt(i, 4);
            }

            tempQueue.policer_entry_list.put(policer_entry.service,policer_entry);
        }

        //------------parametry schedulera--------------
        DefaultTableModel schedulerParamsTableModel = (DefaultTableModel)schedulerParamsTable.getModel();
        //scheduler PRI
        if(schedulerComboBox.getSelectedIndex()==0){
            
            for(int i=0; i< schedulerParamsTableModel.getRowCount(); i++){
                if(((String)schedulerParamsTableModel.getValueAt(i, 0)).equals("priority")){
                    tempQueue.scheduler_params.priority = (String)schedulerParamsTableModel.getValueAt(i, 1);
                }else if(((String)schedulerParamsTableModel.getValueAt(i, 0)).equals("rate [bps]")){
                    tempQueue.scheduler_params.rate = (String)schedulerParamsTableModel.getValueAt(i, 1);
                }
            }

        }else{//scheduler RR,WIRR,WRR
            for(int i=0; i< schedulerParamsTableModel.getRowCount(); i++){
                if(((String)schedulerParamsTableModel.getValueAt(i, 0)).equals("weight")){
                    tempQueue.scheduler_params.weight = (String)schedulerParamsTableModel.getValueAt(i, 1);
                }
            }
        }

        //-----------podkolejki----------------
        DefaultTableModel subqueueParamsTableModel = (DefaultTableModel)subqueueParamsTable.getModel();

        for(int i=0;i<subqueueParamsTableModel.getRowCount();i++){
            Subqueue subqueue = new Subqueue();

            subqueue.ordinal=Integer.toString(i);
            subqueue.min_threshold = (String)subqueueParamsTableModel.getValueAt(i, 1);
            subqueue.max_threshold = (String)subqueueParamsTableModel.getValueAt(i, 2);
            subqueue.probability_dropping = (String)subqueueParamsTableModel.getValueAt(i, 3);
            
            tempQueue.subqueue_list.add(i,subqueue);
        }


        return tempQueue;

    }


    private void saveQueuePolicyToNsdhModel() throws Exception{

        Queue_policy tempQueuePolicy = new Queue_policy();

        tempQueuePolicy.name = queuePolicyNameTextField.getText();
        tempQueuePolicy.mean_packet_size = avgPacketTextField.getText();
        tempQueuePolicy.scheduler = (String)schedulerComboBox.getSelectedItem();

        //model tabeli kolejek
        DefaultTableModel queuesTableModel = (DefaultTableModel)queuesTable.getModel();

        //zapisz aktualny formularz o kolejce
        if(queuesTable.getSelectedRow()!=-1){
            Queue tempQueue = getQueueObjectFromFilledForm();
            tempQueue.name = (String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0);
            tempQueueList.put((String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0), tempQueue);
        }

        //zapisz kolejki do tymczasowego obiektu tempQueuePolicy w zaleznosci czy byly one edytowane czy nie
        for(int i=0; i<queuesTable.getRowCount(); i++){
            String queueName = (String)queuesTableModel.getValueAt(i, 0);

            if(tempQueueList.containsKey(queueName)){ //jesli byla zmieniana to laduj z tymczasowego obiektu
                tempQueuePolicy.queue_list.add(tempQueueList.get(queueName));
            } else if(queuePolicyName != null && !queuePolicyName.equals("")){ //jesli edycja laduj z modelu
                tempQueuePolicy.queue_list.add(nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName).queue_list.get(nsdhController.getQueueIndexOnListInQueuePolicy(nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName),queueName)));
            } else {
                
                createSchedulerParamsTableFields();
                createSubqueueParamsTableFields();
                // w p. p. zaladuj pusta kolejke i zapisz ja do modelu
                //loadPolicerSettingsFromModel(new Queue());
//                loadSchedulerParamsTableFromModel(new Queue());
//                loadSubqueueParamsTableFromModel(new Queue());
                Queue tempQueue = getQueueObjectFromFilledForm();

                tempQueue.name = queueName;
                tempQueuePolicy.queue_list.add(tempQueue);
            }
        }

        //jesli edycja podmien
        if(queuePolicyName != null && !queuePolicyName.equals("")){
            if(queuePolicyName.equals(tempQueuePolicy.name)){
                nsdhController.nsdhModel.network_settings.queue_policy_list.put(queuePolicyName, tempQueuePolicy);
            }else{//jesli zmiana nazwy
                nsdhController.RenameQueuePolicy(queuePolicyName, tempQueuePolicy.name);
                nsdhController.nsdhModel.network_settings.queue_policy_list.put(tempQueuePolicy.name, tempQueuePolicy);
            }
        }else{//jak dodanie nowej polityki
            nsdhController.nsdhModel.network_settings.queue_policy_list.put(tempQueuePolicy.name, tempQueuePolicy);
        }
        

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel avgPacketLabel;
    private javax.swing.JTextField avgPacketTextField;
    private javax.swing.JButton cancelButton;
    private javax.swing.JButton okButton;
    private javax.swing.JComboBox policerComboBox;
    private javax.swing.JLabel policerLabel;
    private javax.swing.JButton policyEntriesAddButton;
    private javax.swing.JPanel policyEntriesPanel;
    private javax.swing.JButton policyEntriesRemoveButton;
    private javax.swing.JScrollPane policyEntriesScrollPane;
    private javax.swing.JTable policyEntriesTable;
    private javax.swing.JLabel queuePolicyNameLabel;
    private javax.swing.JTextField queuePolicyNameTextField;
    private javax.swing.JPanel queuePolicyParamsPanel;
    private javax.swing.JButton queuesAddButton;
    private javax.swing.JPanel queuesPanel;
    private javax.swing.JButton queuesRemoveButton;
    private javax.swing.JScrollPane queuesScrollPane;
    private javax.swing.JTable queuesTable;
    private javax.swing.JComboBox schedulerComboBox;
    private javax.swing.JLabel schedulerLabel;
    private javax.swing.JPanel schedulerParamsPanel;
    private javax.swing.JScrollPane schedulerParamsScrollPane;
    private javax.swing.JTable schedulerParamsTable;
    private javax.swing.JComboBox subqueueCountComboBox;
    private javax.swing.JLabel subqueueCountLabel;
    private javax.swing.JPanel subqueueParamsPanel;
    private javax.swing.JScrollPane subqueueParamsScrollPane;
    private javax.swing.JTable subqueueParamsTable;
    // End of variables declaration//GEN-END:variables

    private NsdhController nsdhController;
    private GraphPanel graphPanel;
    private String queuePolicyName;
    private NetworkSettingsFrame networkSettingsFrame;
    private HashMap<String, Queue> tempQueueList; //tymczasowa lista kolejek ktore byly zmieniane

    //listener selecta z tabeli kolejek - laduje dane kolejki do innych tabel
    private class queueRowSelectionListener implements ListSelectionListener {
        
        int oldSelectedQueueIndex = -1; //indeks starej zaznaczonej kolejki



        public void valueChanged(ListSelectionEvent event) {
            if (event.getValueIsAdjusting()) {
                return;
            }

            //model tabeli kolejek
            DefaultTableModel queuesTableModel = (DefaultTableModel)queuesTable.getModel();

            //zapisz wczesniej uzupelniony formularz o kolejce do tymczasowej tablicy kolejek
            if(oldSelectedQueueIndex!=-1){
                Queue tempQueue = getQueueObjectFromFilledForm();
                tempQueue.name = (String)queuesTableModel.getValueAt(oldSelectedQueueIndex, 0);
                tempQueueList.put((String)queuesTableModel.getValueAt(oldSelectedQueueIndex, 0), tempQueue);
            }

            
            createSchedulerParamsTableFields();
            createSubqueueParamsTableFields();

            if(queuesTable.getSelectedRow()!=-1){

                //laduj dane z tymczasowej listy kolejek jesli taka w niej jest
                if(tempQueueList.containsKey((String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0))){
                    loadPolicerSettingsFromModel(tempQueueList.get((String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0)));
                    loadSchedulerParamsTableFromModel(tempQueueList.get((String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0)));
                    loadSubqueueParamsTableFromModel(tempQueueList.get((String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0)));
                }
                //laduj dane z modelu nsDH jesli edycja i w tempQueueList nie ma kolejki o zaznaczonej nazwie
                else if(queuePolicyName != null && !queuePolicyName.equals("")
                        && nsdhController.getQueueIndexOnListInQueuePolicy(nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName),(String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0))!=-1){
                    loadPolicerSettingsFromModel(nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName).queue_list.get(nsdhController.getQueueIndexOnListInQueuePolicy(nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName),(String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0))));
                    loadSchedulerParamsTableFromModel(nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName).queue_list.get(nsdhController.getQueueIndexOnListInQueuePolicy(nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName),(String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0))));
                    loadSubqueueParamsTableFromModel(nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName).queue_list.get(nsdhController.getQueueIndexOnListInQueuePolicy(nsdhController.nsdhModel.network_settings.queue_policy_list.get(queuePolicyName),(String)queuesTableModel.getValueAt(queuesTable.getSelectedRow(), 0))));
                }else{
                    loadPolicerSettingsFromModel(new Queue());
                    loadSchedulerParamsTableFromModel(new Queue());
                    loadSubqueueParamsTableFromModel(new Queue());
                }
            }
            
            oldSelectedQueueIndex = queuesTable.getSelectedRow();
        }
    }

}
